<template>
	<app-layout>
		<view>
			<app-card-detail :rules="ruless" :list="detail" qrpath="pages/consumer/clerkcoupon/clerkcoupon">
			</app-card-detail>
		</view>
	</app-layout>
</template>

<script>
	import {
		mapGetters,
		mapState
	} from 'vuex';
	import appCardDetail from '../components/app-card-detail.vue';
	const base64 = require('../../../utils/base64.js');

	export default {
		components: {
			appCardDetail
		},
		data() {
			return {
				detail: null,
				qrimg: '',
				ruless: ''
			}
		},
		onLoad(options) {
			// this.getQr(options.id)
			this.onReq(261)
			this.getDetail(options.id);
		},
		computed: {
			...mapState({
				userInfo: state => state.user.info
			}),
		},
		methods: {
			onReq(kid) {
				this.$request({
					url: this.$api.navs.catedetail,
					data: {
						keyword: kid
					}
				}).then((res) => {
					if (kid == 261) {
						this.ruless = res.data.list[0].params.describe
					}
				}).catch(() => {

				})
			},
			getQr(id, memuid) {
				let that = this;
				// console.log('***');
				// console.log(that.userInfo);
				// path: '/pages/user-center/groupcoup/groupcoup',
				// shareid: this.userInfo.options.user_id,

				that.$showLoading({
					text: '加载中...'
				});
				that.$request({
					url: that.$api.generate.appcode,
					method: 'post',
					data: {
						path: "pages/consumer/clerkcoupon/clerkcoupon",
						width: 750,
						scene: "id=" + id + "&uid=" + memuid
					},
				}).then(response => {
					that.$hideLoading();
					if (response.code === 0) {
						that.qrimg = response.data.qrcode;
					} else {
						uni.showToast({
							title: response.msg,
							icon: 'none',
							duration: 1000,
						});
					}
				}).catch(() => {
					that.$hideLoading();
				});
			},
			getDetail(id) {
				let that = this;
				that.$showLoading({
					text: '加载中...'
				});
				that.$request({
					url: that.$api.voucher.list,
					data: {
						user_id: that.userInfo.options.user_id,
						id: id
					},
				}).then(response => {
					that.$hideLoading();
					if (response.code === 0) {
						that.detail = response.data.list[0];
					} else {
						uni.showToast({
							title: response.msg,
							icon: 'none',
							duration: 1000,
						});
					}
				}).catch(() => {
					that.$hideLoading();
				});
			},
		},
	}
</script>
